package org.example.elmfront.mapper;

import org.apache.ibatis.annotations.*;
import org.example.elmfront.entity.Product;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Select("SELECT * FROM product")
    List<Product> findAllProducts();


    // 根据产品 ID 查询产品
    @Select("SELECT * FROM product WHERE id = #{id}")
    Product findProductById(@Param("id") Long id);


    // 根据餐厅 ID 查询产品
    @Select("SELECT * FROM product WHERE restaurant_id = #{restaurantId}")
    List<Product> findProductsByRestaurantId(@Param("restaurantId") Long restaurantId);


    // 插入产品
    @Insert("INSERT INTO product (name, price, restaurant_id) VALUES (#{name}, #{price}, #{restaurant.id})")
    int insertProduct(Product product);


    // 更新产品
    @Update("UPDATE product SET name = #{name}, price = #{price}, restaurant_id = #{restaurant.id} WHERE id = #{id}")
    int updateProduct(Product product);


    // 删除产品
    @Delete("DELETE FROM product WHERE id = #{id}")
    int deleteProductById(@Param("id") Long id);

}